﻿#include <iostream>
#include <locale>
#include <string>
#include <fstream>
#include "fcjson/fcjson.h"

#pragma execution_character_set("utf-8")

#if  0
#define TEST_JSON_FILE  "data.json"
#else
#define TEST_JSON_FILE  "city_4.json"
#endif

int count = 1;
int dump_indent = 4;

int main()
{
    setlocale(LC_ALL, "zh_CN.UTF-8");
    system("chcp 65001");


    fcjson::json_value val;
    val.parse("\xEF\xBB\xBF{\"name\":\"FC\"}");
    val.parse_from_file("test.json");

    // 构造 JSON 对象
    std::cout << "构造 JSON 对象" << std::endl;
    {
        fcjson::json_value val = fcjson::json_object{
            { _T("null"), nullptr},
            { _T("bool_false"), false },
            { _T("bool_true"), true },
            { _T("int_min"), INT64_MIN },
            { _T("int_max"), INT64_MAX },
            { _T("uint_max"), UINT64_MAX },
            { _T("float"), 3.1415926535 },
            { _T("string_empty"), _T("")},
            { _T("object"), fcjson::json_object{
                    { _T("name"), _T("我是地球🌍") },
                    { _T("age"), 30 }
                },
            },
            { _T("array"), fcjson::json_array{
                nullptr,
                false, true, INT64_MIN, INT64_MAX, 3.1415926535
                }
            }
        };

        val.dump_to_binary_file(_T("json_bin.jsb"));
        val.dump_to_file(_T("json_text.json"), 0);
    }

    {
        fcjson::json_value val;

        val.parse_from_binary_file(_T("json_bin.jsb"));
        val.dump_to_binary_file(_T("json_bin2.jsb"));
        val.dump_to_file(_T("json_bin2.json"), 0);

        val.parse_from_file(_T("json_text.json"));
        val.dump_to_file(_T("json_text2.json"));
    }

    {
        fcjson::json_value val;

        val.parse_from_binary_file(_T("json_bin2.jsb"));
        val.dump_to_binary_file(_T("json_bin3.jsb"));
        val.dump_to_file(_T("json_bin3.json"), 0);
    }

    return 0;
}
